#include <stdio.h>
#include <stdlib.h>

void InputArray(int* array, int num) {
    printf("please input the elements of array:");
    for (int i = 0; i < num; i++)
        scanf("%d", &array[i]);
}

void ArrayPrint(int* array, int num) {
    printf("after sorting, the elements are:");
    for (int i = 0; i < num; i++) 
        printf("%d ", array[i]);
    printf("\n");
}

void SelectSort(int* array, int length) {
    int left = 0, right = length - 1;
    while (left <= right) {
        int maxi = left;
        for (int i = left + 1; i <= right; ++i) {
            if (array[i] > array[maxi])
                maxi = i;
        }
        int temp = array[maxi];
        array[maxi] = array[left];
        array[left] = temp;
        ++left;
    }
}

int main() {
    int num = 0;
    printf("please input the number of array:");
    scanf("%d", &num);
    int* array = (int*)malloc(sizeof(int) * num);
    InputArray(array, num);
    SelectSort(array, num);
    ArrayPrint(array, num);
    free(array);
    return 0;
}
